//
//  UserVM.m
//  HTP
//
//  Created by admin on 15/11/10.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "UserVM.h"

@implementation UserVM
-(void)userLogin:(NSString *)userName andPwd:(NSString *)userPwd withUserType:(NSString *)userType{
    tns1_loginCheck *loginCheck = [[tns1_loginCheck alloc] init];
    loginCheck.userName = userName;
    loginCheck.password = userPwd;
    loginCheck.userType = userType; //家长端是2
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding loginCheckUsingParameters:loginCheck headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];
    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}

- (void)profileUpdate:(NSNumber *)prId prChilrName:(NSString *)prChilrName prChildSex:(NSNumber *)prChildSex userBirth:(NSString *)userBirth prChildSchool:(NSString *)prChildSchool prAddr:(NSString *)prAddr prChildPhoto:(NSString *)prChildPhoto prMotto:(NSString *)prMotto {
    tns1_updateParentInfo *updateInfo = [[tns1_updateParentInfo alloc] init];
    updateInfo.prId = [NSString stringWithFormat:@"%@",prId];
    updateInfo.prChildName = prChilrName;
    updateInfo.prChildSex = [NSString stringWithFormat:@"%@",prChildSex];
    updateInfo.userBirth = userBirth;
    updateInfo.prChildSchool = prChildSchool;
    updateInfo.prAddr = prAddr;
    updateInfo.prMotto = prMotto;
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding updateParentInfoUsingParameters:updateInfo headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];
    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}

-(void)imageUpload:(NSString *)imageString andFileName:(NSString *)fileName{
    tns1_uploadImage *uploadImage = [[tns1_uploadImage alloc] init];
    uploadImage.image = imageString;
    uploadImage.userID = @"";
    uploadImage.filename = fileName;
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding uploadImageUsingParameters:uploadImage headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];
    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}

-(void)updateUserPhoto:(NSString *)userId photoUrl:(NSString *)photo{
    tns1_uploadUserPhotoByUrl *updatePhoto = [[tns1_uploadUserPhotoByUrl alloc] init];
    updatePhoto.userId = userId;
    updatePhoto.imageUrl = photo;
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding uploadUserPhotoByUrlUsingParameters:updatePhoto headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];
    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}
-(void)userRegister:(NSString *)usereName andPwd:(NSString *)userPwd{
    tns1_userRegisterForParent *userRegister = [[tns1_userRegisterForParent alloc] init];
    userRegister.userName = usereName;
    userRegister.passWord = userPwd;
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding userRegisterForParentUsingParameters:userRegister headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];
    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}
-(void)sendRands:(NSString *)userName andSMSRand:(NSString *)rand{
    tns1_addValidatecodeSmsInfo *addValidate = [[tns1_addValidatecodeSmsInfo alloc] init];
    addValidate.phoneNumber = userName;
    addValidate.smsContent = rand;
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding addValidatecodeSmsInfoUsingParameters:addValidate headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];

    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}
- (void)updateUserPwd:(NSString *)userId password:(NSString *)password oldPassword:(NSString *)oldpwd {
    tns1_updateUserPassword *updatePwd = [[tns1_updateUserPassword alloc] init];
    updatePwd.userId = userId;
    updatePwd.password = password;
    updatePwd.oldPassword = oldpwd;
    [WSDLNetWork shareInstance:^interfaceSoapBindingResponse *(interfaceSoapBinding *binding) {
        return [binding updateUserPasswordUsingParameters:updatePwd headerElements:nil];
    } withResult:^(NSDictionary *message) {
        [self fetchResult:message];
        
    } throwError:^(NSError *error) {
        [self fetchError];
    }];
}
@end
